<?php
date_default_timezone_set('Asia/Shanghai');
setlocale(LC_ALL, 'En-Us');
set_time_limit(0); //不限制超时时间
ini_set('display_errors', "on");
error_reporting(E_ALL & ~E_STRICT & ~E_NOTICE);
ini_set('memory_limit','1024M');

define("ROOT", __DIR__.'/');
define("LOGPATH", ROOT.'log/');
define("SYSLOG", ROOT.'log/sys.log');
define("OPEN_DEBUG", true);

require_once ROOT.'library/filelog.php';
require_once ROOT.'library/fatelError.php';
require_once ROOT.'bin/crontabBase.php';

$params = array();
foreach($argv as $v)
{
    if(false === strpos($v, '='))
    {
        continue;
    }
    $result = explode('=', $v);
    if($result[0] && ('' !== $result[1]))
    {
        $params[$result[0]] = $result[1];
    }
}

$class = $argv[1];
$method = $argv[2];
$classpath = ROOT."bin/{$class}.php";

if(!file_exists($classpath))
{
    $errmsg = "class:{$class} not exist";
    filelog::save($errmsg, SYSLOG);
    exit($errmsg.PHP_EOL);
}

try{
    register_shutdown_function(array('fatalError', 'catchFatalError'));
    require_once $classpath;

    $classObj = new $class($method, $params);
    $classObj->run();
    $obj = null;
    unset($obj);
} catch (Exception $e) {
    $errmsg = '['.date('Y-m-d H:i:s').'] 错误代码：'.$e->getCode()."\t 错误信息：".$e->getMessage()."\t 文件：".$e->getFile() ."\t 行号：".$e->getLine();
    //"\t 路由信息：".$e->getTraceAsString();
    filelog::save($errmsg, SYSLOG);
    exit($errmsg.PHP_EOL);
}


